﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using Do_an_C_sharp.DAL;


namespace Do_an_C_sharp.BLL
{
    class NhaCungCapController
    {
        DemoDataContext db = new DemoDataContext();
        public List<NhaCungCap> laykhach()
        {
            return db.NhaCungCaps.ToList();
        }

        public List<NhaCungCap> timma(string ma)
        {
            return db.NhaCungCaps.Where(ncc => ncc.MANHACUNGCAP == ma).ToList();
        }
        public List<NhaCungCap> timten(string ten)
        {
            return db.NhaCungCaps.Where(ncc => ncc.TENNHACUNGCAP.Contains(ten)).ToList();
        }
        public NhaCungCap timelement(string ma)
        {
            return db.NhaCungCaps.Where(ncc => ncc.MANHACUNGCAP == ma).FirstOrDefault();
        }
        public void them(string ma,string ten,string diachi,string dienthoai,string email)
        {
            //xây dựng chưa hoàn thiện
            NhaCungCap ncc = new NhaCungCap();
            ncc.MANHACUNGCAP = ma;
            ncc.TENNHACUNGCAP = ten;
            ncc.DIACHI = diachi;
            ncc.DIENTHOAI = dienthoai;
            ncc.EMAIL = email;
            db.NhaCungCaps.InsertOnSubmit(ncc);
        }
        public void xoa(string ma)
        {
            db.NhaCungCaps.DeleteOnSubmit(timelement(ma));
            //db.SubmitChanges();
        }
        public bool sua(string ma, string ten, string diachi, string dienthoai, string email)
        {
            //mới xây dựng để sửa mô tả thôi
            NhaCungCap h = timelement(ma);
            if (h != null)
            {
                h.TENNHACUNGCAP = ten;
                h.DIACHI = diachi;
                h.DIENTHOAI = dienthoai;
                h.EMAIL = email;
                return true;
            }
            return false;
        }
        public void luu()
        {
            db.SubmitChanges();
        }
    }
}
